home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / UTILITIE / UNIX_COH / 2772.ZIP / DUMPSCRE.TAZ / DUMPSCRE.tar
Text File  |  1991-07-02  |  1KB  |  58 lines

  1. /*
  2.  * dumpscreen:    take a snapshot of the screen and copy it to stdout.
  3.  *        note: does not preserve screen attributes.
  4.  * usage:    dumpscreen [-c]
  5.  *        use the -c option if using a color video card.
  6.  */
  7. #include <stdio.h>
  8.  
  9. #define    USAGE  "usage:  dumpscreen [-c]\n\tUse the -c option with a color card."
  10. #define    CHARS_PER_LINE    80
  11. #define    LINES        25
  12. #define    MEM        "/dev/mem"
  13. #define    MONO_OFFSET    0xB0000L    /* start of monochrome screen memory */
  14. #define    COLOR_OFFSET    0xB8000L    /* start of color screen memory */
  15.  
  16. long    offset = MONO_OFFSET;        /* default to mono display adaptor */
  17. char    screen[CHARS_PER_LINE * LINES * 2];
  18.  
  19. main(argc, argv)
  20. int    argc;
  21. char    *argv[];
  22. {
  23.     register char    *cp;
  24.     register int    row, col;
  25.     FILE *fp;
  26.  
  27.     if (argc == 2) {
  28.         if (argv[1][0] != '-' || argv[1][1] != 'c')
  29.             usage();
  30.         else
  31.             offset = COLOR_OFFSET;
  32.     } else if (argc != 1)
  33.         usage();
  34.     if ((fp = fopen(MEM, "rb")) == NULL)
  35.         fatal("unable to access %s", MEM);
  36.     fseek(fp, offset, 0);
  37.     if (fread(screen, sizeof screen, 1, fp) != 1)
  38.         fatal("unable to read screen memory");
  39.     for (cp = screen, row = 0; row < LINES; ++row) {
  40.         for (col = 0; col < CHARS_PER_LINE; ++col, cp += 2)
  41.             putchar(*cp);
  42.         putchar('\n');
  43.     }
  44.     exit(0);
  45. }
  46.  
  47. usage()
  48. {
  49.     fatal(USAGE);
  50. }
  51.  
  52. fatal(arg)
  53. char    *arg;
  54. {
  55.     fprintf(stderr, "dumpscreen: %r\n", &arg);
  56.     exit(1);
  57. }
  58.